package com.lanou.sfu.songforu.adapter;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lanou.sfu.songforu.R;
import com.lanou.sfu.songforu.entity.ArtistListEntity;

import java.util.List;

import it.sephiroth.android.library.picasso.Picasso;


/**
 * Created by dllo on 15/10/26.
 */
public class HotArtistAllAdapter extends BaseAdapter {
    private Context mcontext;
    private List<ArtistListEntity.ArtistEntity> datas;

    public HotArtistAllAdapter(Context context){
        mcontext = context;

    }

    //设置数据
    public void setData(List<ArtistListEntity.ArtistEntity> datas) {
        this.datas = datas;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        if (datas != null && datas.size() > 0){
            return datas.size();
        } else {
        return 0;
        }
    }

    @Override
    public ArtistListEntity.ArtistEntity getItem(int position) {
        if (datas != null && datas.size()> 0){
            return datas.get(position);
        } else {
            return null;
        }
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Log.i("hh", datas.size()+ "");
        ViewHolder holder = null;
        if (convertView == null){
            convertView = View.inflate(mcontext, R.layout.hot_artist_gridview_item,null);
            holder = new ViewHolder();
            holder.artistName = (TextView) convertView.findViewById(R.id.hot_artist_item_textView);
            holder.artistPic = (ImageView) convertView.findViewById(R.id.hot_artist_item_imageView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        ArtistListEntity.ArtistEntity artistEntity = getItem(position);
        Log.i("lanou", artistEntity + " 8888");
        if (artistEntity != null){
            holder.artistName.setText(artistEntity.getName());
            Picasso.with(mcontext).load(artistEntity.getAvatar_big()).into(holder.artistPic);
        }

        return convertView;
    }


    public class ViewHolder{
        private ImageView artistPic;
        private TextView artistName;
    }

}
